package com.example.store.config;

import com.example.store.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;
@Configuration//加载当前的拦截器
public class LoginInterceptorConfig implements WebMvcConfigurer {
    //创建拦截器对象
    HandlerInterceptor interceptor = new LoginInterceptor();

    /**拦截器配置**/
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //白名单
        List<String> patterns = new ArrayList<String>();
        patterns.add("/bootstrap3/**");
        patterns.add("/css/**");
        patterns.add("/images/**");
        patterns.add("/js/**");
        patterns.add("/web/register.html");
        patterns.add("/web/login.html");
        patterns.add("/web/index.html");
        patterns.add("/web/product.html");
        patterns.add("/user/reg");
        patterns.add("/user/login");
        patterns.add("/districts/**");
        patterns.add("/product/**");
        //通过注册工具添加拦截器
        registry.addInterceptor(interceptor)
            .addPathPatterns("/**")
            .excludePathPatterns(patterns);
    }

}
